<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
    <asp:GridView ID="GridViewRaids" runat="server" AutoGenerateColumns="False" CellPadding="4"
        DataKeyNames="RaidID" DataSourceID="SqlDataSource_Raids" ForeColor="#333333" GridLines="None">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:CommandField ShowSelectButton="True" />
            <asp:BoundField DataField="RaidID" HeaderText="RaidID" InsertVisible="False" ReadOnly="True"
                SortExpression="RaidID" />
            <asp:BoundField DataField="Instance" HeaderText="Instance" SortExpression="Instance" />
            <asp:BoundField DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime" />
            <asp:BoundField DataField="EndTime" HeaderText="EndTime" SortExpression="EndTime" />
        </Columns>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <br />
    <asp:GridView ID="GridView_RaidSummaryMeters" runat="server" AllowSorting="True" AutoGenerateColumns="False"
        BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
        CellPadding="3" DataSourceID="SqlDataSource_RaidMeters" ForeColor="Black" GridLines="Vertical" OnRowCommand="GridView_RaidSummaryMeters_RowCommand" AllowPaging="True">
        <FooterStyle BackColor="#CCCCCC" />
        <Columns>
            <asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject">
                <ItemStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="TimeInCombat" DataFormatString="{0:#.}" HeaderText="TimeInCombat"
                HtmlEncode="False" ReadOnly="True" SortExpression="TimeInCombat">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="DamageOut" DataFormatString="{0:#.}" HeaderText="DamageOut"
                HtmlEncode="False" ReadOnly="True" SortExpression="DamageOut">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="DPS" DataFormatString="{0:#.00}" HeaderText="DPS" HtmlEncode="False"
                ReadOnly="True" SortExpression="DPS">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="DamageIn" DataFormatString="{0:#.}" HeaderText="DamageIn"
                HtmlEncode="False" ReadOnly="True" SortExpression="DamageIn">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="HealingOut" DataFormatString="{0:#.}" HeaderText="HealingOut"
                HtmlEncode="False" ReadOnly="True" SortExpression="HealingOut">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="HPS" DataFormatString="{0:#.00}" HeaderText="HPS" HtmlEncode="False"
                ReadOnly="True" SortExpression="HPS">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="HealingIn" DataFormatString="{0:#.}" HeaderText="HealingIn"
                HtmlEncode="False" ReadOnly="True" SortExpression="HealingIn">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:HyperLinkField DataNavigateUrlFields="NounID" DataNavigateUrlFormatString="PersonDetail.aspx?PersonID={0}"
                Text="View Detail" />
        </Columns>
        <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="#CCCCCC" />
    </asp:GridView>
    <br />
    <asp:GridView ID="GridView_RaidFights" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource_RaidFights" ForeColor="#333333" GridLines="None" OnRowCommand="GridView_RaidFights_RowCommand" AllowPaging="True">
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:BoundField DataField="BeginTime" DataFormatString="{0:T}" HeaderText="BeginTime"
                HtmlEncode="False" SortExpression="BeginTime" />
            <asp:BoundField DataField="EndTime" DataFormatString="{0:t}" HeaderText="EndTime"
                HtmlEncode="False" SortExpression="EndTime" />
            <asp:BoundField DataField="FightID" HeaderText="FightID" InsertVisible="False" SortExpression="FightID"
                Visible="False" />
            <asp:BoundField DataField="Duration" DataFormatString="{0:m:ss}" HeaderText="Duration"
                HtmlEncode="False" SortExpression="Duration">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="Recovery" DataFormatString="{0:m:ss}" HeaderText="Recovery"
                HtmlEncode="False" SortExpression="Recovery">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="DamageOut" DataFormatString="{0:#.}" HeaderText="DamageOut"
                HtmlEncode="False" SortExpression="DamageOut">
                <ItemStyle HorizontalAlign="Right" />
            </asp:BoundField>
            <asp:BoundField DataField="LastDeath" HeaderText="LastDeath" SortExpression="LastDeath" />
            <asp:HyperLinkField DataNavigateUrlFields="FightID" DataNavigateUrlFormatString="FightDetail.aspx?FightID={0}"
                Text="View Detail" />
        </Columns>
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <EditRowStyle BackColor="#999999" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
    </asp:GridView>
    <br />
    <asp:SqlDataSource ID="SqlDataSource_Raids" runat="server" ConnectionString="<%$ ConnectionStrings:RaidLog.Engine.Properties.Settings.RaidLogConnectionString %>"
        ProviderName="<%$ ConnectionStrings:RaidLog.Engine.Properties.Settings.RaidLogConnectionString.ProviderName %>"
        SelectCommand="SELECT [RaidID], [Instance], [StartTime], [EndTime] FROM [mtRaid]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource_RaidMeters" runat="server" ConnectionString="<%$ ConnectionStrings:RaidLog.Engine.Properties.Settings.RaidLogConnectionString %>"
        ProviderName="<%$ ConnectionStrings:RaidLog.Engine.Properties.Settings.RaidLogConnectionString.ProviderName %>"
        SelectCommand="select &#13;&#10;&#9;&#9;vFightMeters.NounID,&#13;&#10;&#9;&#9;vFightMeters.Subject, &#13;&#10;&#9;&#9;sum(vFightMeters.TimeInCombat) TimeInCombat,&#13;&#10;&#9;&#9;sum(vFightMeters.DamageOut) DamageOut,&#13;&#10;&#9;&#9;sum(vFightMeters.DamageOut)/sum(vFightMeters.TimeInCombat) DPS,&#13;&#10;&#9;&#9;sum(vFightMeters.DamageIn) DamageIn,&#13;&#10;&#9;&#9;sum(vFightMeters.HealingOut) HealingOut,&#13;&#10;&#9;&#9;sum(vFightMeters.HealingOut)/ sum(vFightMeters.TimeInCombat) HPS,&#13;&#10;&#9;&#9;sum(vFightMeters.HealingIn) HealingIn&#13;&#10;&#9;from vFightMeters&#13;&#10;&#9;&#9;inner join faaFight on faaFight.FightID = vFightMeters.FightID&#13;&#10;&#9;where faaFight.RaidID = @RaidID&#13;&#10;&#9;group by faaFight.RaidID, vFightMeters.NounID, vFightMeters.Subject" OnSelecting="SqlDataSource2_Selecting">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridViewRaids" DefaultValue="0" Name="RaidID" PropertyName="SelectedValue"
                Size="31" />
        </SelectParameters>
    </asp:SqlDataSource><asp:SqlDataSource ID="SqlDataSource_RaidFights" runat="server" ConnectionString="<%$ ConnectionStrings:RaidLog.Engine.Properties.Settings.RaidLogConnectionString %>"
        ProviderName="<%$ ConnectionStrings:RaidLog.Engine.Properties.Settings.RaidLogConnectionString.ProviderName %>"
        SelectCommand="with DeathLog(FightID, SubjectID, DeathNumber) as (&#13;&#10;&#9;select FightID, SubjectID, ROW_NUMBER() OVER (PARTITION BY FightID ORDER BY [Time]) DeathNumber &#13;&#10;&#9;from mtDeath &#13;&#10;&#9;&#9;inner join faaFight on faaFight.BeginTime <= mtDeath.[Time] and faaFight.EndTime >= mtDeath.[Time] and faaFight.RaidID = mtDeath.RaidID&#13;&#10;), LastDeathIndex(FightID, DeathNumber) as (&#13;&#10;&#9;select FightID, Max(DeathNumber) from DeathLog group by FightID&#13;&#10;), DamageList(RaidID, FightID, BeginTime, EndTime, DamageOut, Sequence) as (&#13;&#10;&#9;select faaFight.RaidID, faaFight.FightID, faaFight.BeginTime, faaFight.EndTime, Sum([Value]) DamageOut, ROW_NUMBER() OVER (PARTITION BY faaFight.RaidID ORDER BY faaFight.BeginTime) Sequence&#13;&#10;&#9;from faaFight&#13;&#10;&#9;&#9;inner join faaMeter4d on faaFight.FightID = faaMeter4d.FightID&#13;&#10;&#9;where MeterTypeID = 1&#13;&#10;&#9;group by faaFight.RaidID, faaFight.FightID, faaFight.BeginTime, faaFight.EndTime&#13;&#10;), XDamageList(RaidID, FightID, BeginTime, EndTime, Duration, Recovery, DamageOut) as (&#13;&#10;&#9;select A.RaidID, A.FightID, A.BeginTime, A.EndTime,A.EndTime - A.BeginTime,B.BeginTime - A.EndTime, A.DamageOut&#13;&#10;&#9;from DamageList A full outer join DamageList B on B.Sequence = A.Sequence + 1 and A.RaidID = B.RaidID&#13;&#10;)&#13;&#10;&#9;select XDamageList.RaidID, XDamageList.FightID, XDamageList.BeginTime, XDamageList.EndTime, XDamageList.Duration, XDamageList.Recovery, XDamageList.DamageOut, LastDeath.PublicText LastDeath&#13;&#10;&#9;from XDamageList&#13;&#10;&#9;&#9;inner join LastDeathIndex on XDamageList.FightID = LastDeathIndex.FightID&#13;&#10;&#9;&#9;inner join DeathLog on XDamageList.FightID = DeathLog.FightID and DeathLog.DeathNumber = LastDeathIndex.DeathNumber&#13;&#10;&#9;&#9;inner join mtNoun LastDeath on LastDeath.NounID = DeathLog.SubjectID&#13;&#10;&#9;where XDamageList.RaidID = @RaidID&#13;&#10;&#9;order by XDamageList.BeginTime, XDamageList.EndTime" OnSelecting="SqlDataSource2_Selecting">
        <SelectParameters>
            <asp:ControlParameter ControlID="GridViewRaids" DefaultValue="0" Name="RaidID" PropertyName="SelectedValue"
                Size="31" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

